/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainPalette.java
 *
 * Created on 23-mar-2011, 15:11:18
 */

package org.itver.gui.visual.palette;

import java.awt.event.ActionListener;

/**
 *
 * @author pablo
 */
public class MainPalette extends javax.swing.JFrame {

    public static String ACCEPT_BTN = "accept";
    public static String CANCEL_BTN = "cancel";
    /** Creates new form MainPalette */
    public MainPalette() {
        initComponents();
        this.setSize(400, 500);
        this.setResizable(false);
    }

    public void addCategory(CategoryPalette category){
        this.tabPanel.add(category.getTitle(), category);
    }

    public ItemPalette getSelectedItem(){
        if(this.tabPanel.getSelectedComponent() instanceof CategoryPalette){
            CategoryPalette cat = (CategoryPalette) this.tabPanel.getSelectedComponent();
            return cat.getSelectedItem();
        }
        return null;
    }

    public String getSelectedCategoryName(){
        CategoryPalette cat = (CategoryPalette) this.tabPanel.getSelectedComponent();
        return cat.getTitle();
    }

    public void addActionListener(ActionListener al){
        this.accept.addActionListener(al);
    }

    public void removeActionListener(ActionListener al){
        this.accept.removeActionListener(al);
    }


    public CategoryPalette getCategory(String title){
        for(int i = 0 ; i < tabPanel.getTabCount(); i++)
            if(tabPanel.getTitleAt(i).equals(title))
                return (CategoryPalette) tabPanel.getComponentAt(i);
        return null;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabPanel = new javax.swing.JTabbedPane();
        javax.swing.JPanel jPanel1 = new javax.swing.JPanel();
        cancel = new javax.swing.JButton();
        accept = new javax.swing.JButton();

        setLayout(new java.awt.BorderLayout());

        tabPanel.setTabPlacement(javax.swing.JTabbedPane.LEFT);
        add(tabPanel, java.awt.BorderLayout.CENTER);

        jPanel1.setOpaque(false);
        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        cancel.setText(org.openide.util.NbBundle.getMessage(MainPalette.class, "MainPalette.cancel.text")); // NOI18N
        cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelActionPerformed(evt);
            }
        });
        jPanel1.add(cancel);

        accept.setText(org.openide.util.NbBundle.getMessage(MainPalette.class, "MainPalette.accept.text")); // NOI18N
        accept.setSelected(true);
        accept.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                acceptActionPerformed(evt);
            }
        });
        jPanel1.add(accept);

        add(jPanel1, java.awt.BorderLayout.SOUTH);
    }// </editor-fold>//GEN-END:initComponents

    private void acceptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_acceptActionPerformed

    private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_cancelActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton accept;
    private javax.swing.JButton cancel;
    private javax.swing.JTabbedPane tabPanel;
    // End of variables declaration//GEN-END:variables

}
